<?php
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
  <head>
      <title>Netsuite - Bitzer</title>
      <!--<link rel="StyleSheet" href="assets/css/style.css" type="text/css" />-->

  </head>
  <body>

      <?php
            
            include("../includes/custom/bal_netsuite.php");


            $bal = new BAL();

            $bal->setSearchKeyword($_SERVER["QUERY_STRING"]);

            $list_names = $bal->getListNames();

            $all_current_list_items = $bal->getCountAtCurrentLevel();

      ?>

       <table data-bitzer-data="true"
              data-bitzer-title="Netsuite"
              data-bitzer-desc="Netsuite"
              data-bitzer-component="options"
              data-bitzer-record-count="<?php echo $all_current_list_items; ?>"
              <?php
                if(!isset ($bal->params["recordCount"]) || $bal->params["recordCount"][0] == "N")
                {
              ?>
              data-bitzer-number-of-rows="<?php echo count($list_names); ?>"
              data-bitzer-start-index="<?php if(isset ($bal->params['startRow'])) { echo $bal->params['startRow'][0]; } else { echo "0"; } ?>"
              <?php
                }
              ?>
              width="100%">

           <?php
                if(isset ($bal->params["recordCount"]) && $bal->params["recordCount"][0] == "Y")
                {
           ?>
                    <tr>
                        <td>Record Count</td>
                        <td><?php echo $db->getRecordsCount("options"); ?></td>
                    </tr>

           <?php
                }
                else
                {
           ?>

         <tr>
             <?php
                $first_list = $list_names[0];

                if(!is_null($first_list))
                {
                foreach($first_list as $header => $value)
                {
                    if(!is_numeric($header))
                    {
                        if($header == "id")
                        {
             ?>
                            <th data-bitzer-field="id" data-bitzer-key-order="1">ID</th>
             <?php
                        }
                        else if($header == "list_label")
                        {
             ?>
                            <th data-bitzer-field="list_label">List</th>
             <?php
                        }
                        else if($header == "image_url")
                        {
             ?>
                            <th data-bitzer-field="image_url">Image Path</th>
             <?php
                        }
                        else if($header == "last_modified")
                        {
             ?>
                            <th data-bitzer-field="lastModifiedOn">Last Modified On</th>
             <?php
                        }
                    }
                }
                }
             ?>

         </tr>

         <?php
            if(is_array($list_names))
            {
                foreach($list_names as $list)
                {
                    
         ?>

                    <tr data-bitzer-pk-name="id"
                        data-bitzer-pk-value="<?php echo $list["id"]; ?>">

                        <?php
                            foreach($list as $property => $value)
                            {
                                if(!is_numeric($property))
                                {
                        ?>
                                <td><?php

                                    if($property == "image_url")
                                    {
                                        ?><img src="web/assets/icons/<?php echo trim($value); ?>" /><?php
                                    }
                                    else
                                    {
                                        echo trim($value);
                                    }
                                    ?></td>
                        <?php
                                }
                            }
                        ?></tr>
         <?php
                }
            }
                }
         ?>
       </table>
  </body>
</html>